#pragma once

#include "types.h"
#include "util.h"
#include "thread.h"
#include "Object.h"
#include "class_file.h"
#include <map>
using namespace std;
class RuntimeEnvironment{
public:
private:
	vector<Object> ObjectHeap;
	map<string,ClassFile> ClassHeap;
	ClassFile *mainClass;
	Thread mainThread;
	static RuntimeEnvironment instance;
private:
	Object createObject(string className){
		ClassFile javaClass = ClassHeap[className];
		char *startAddr = (char*)&javaClass;
		int length = sizeof(javaCalss);
		char *dump = new char[length];
		char *p = dump;
		for(int i = 0; i < length; i++) {
			*p++ = *startAddr++;
		}
		Object res(OBJECT_T,dump);
		ObjectHeap.push_back(res);
		return res;
	}

	RuntimeEnvironment() {};
public:
	static RuntimeEnvironment getRuntimeEnvironment() {
		return instance;
	}
	void init(int argc, char *argv[]);
	void startVM();
};